using System;
using System.Data.SqlTypes;
using System.Data;
using Jalal.Library.Utility;
using Jalal.Library.Data;
using BCGC.DAL;
namespace BCGC.BLL.BusinessObject.UserAccount
{
    public class UserProfile
    {
        private int id;
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private String realName;
        public String RealName
        {
            get
            {
                return realName;
            }
            set
            {
                realName = value;
            }
        }

        private String nickName;
        public String NickName
        {
            get
            {
                return nickName;
            }
            set
            {
                nickName = value;
            }
        }

        private String city;
        public String City
        {
            get
            {
                return city;
            }
            set
            {
                city = value;
            }
        }

        private DateTime dateOfBirth;
        public DateTime DateOfBirth
        {
            get
            {
                return dateOfBirth;
            }
            set
            {
                dateOfBirth = value;
            }
        }

        private String messenger;
        public String Messenger
        {
            get
            {
                return messenger;
            }
            set
            {
                messenger = value;
            }
        }

        private String facebookProfileUrl;
        public String FacebookProfileUrl
        {
            get
            {
                return facebookProfileUrl;
            }
            set
            {
                facebookProfileUrl = value;
            }
        }

        private String mood;
        public String Mood
        {
            get
            {
                return mood;
            }
            set
            {
                mood = value;
            }
        }

        private String playerStyle;
        public String PlayerStyle
        {
            get
            {
                return playerStyle;
            }
            set
            {
                playerStyle = value;
            }
        }

        private String element;
        public String Element
        {
            get
            {
                return element;
            }
            set
            {
                element = value;
            }
        }

        private String realImageUrl;
        public String RealImageUrl
        {
            get
            {
                return realImageUrl;
            }
            set
            {
                realImageUrl = value;
            }
        }

        private bool isRealImageVerified;
        public bool IsRealImageVerified
        {
            get
            {
                return isRealImageVerified;
            }
            set
            {
                isRealImageVerified = value;
            }
        }

        private String avatarImageUrl;
        public String AvatarImageUrl
        {
            get
            {
                return avatarImageUrl;
            }
            set
            {
                avatarImageUrl = value;
            }
        }

        private bool isAvatarImageVerified;
        public bool IsAvatarImageVerified
        {
            get
            {
                return isAvatarImageVerified;
            }
            set
            {
                isAvatarImageVerified = value;
            }
        }

        private String favoriteGames;
        public String FavoriteGames
        {
            get
            {
                return favoriteGames;
            }
            set
            {
                favoriteGames = value;
            }
        }

        private String userBio;
        public String UserBio
        {
            get
            {
                return userBio;
            }
            set
            {
                userBio = value;
            }
        }

        private bool useProfileImage;
        public bool UseProfileImage
        {
            get
            {
                return useProfileImage;
            }
            set
            {
                useProfileImage = value;
            }
        }

        private int userId;
        public int UserId
        {
            get { return userId; }
            set { userId = value; }
        }

        private string memberId;
        public string MemberId
        {
            get { return memberId; }
            set { memberId = value; }
        }

        private int weeklyGamingScore;
        public int WeeklyGamingScore
        {
            get { return weeklyGamingScore; }
            set { weeklyGamingScore = value; }
        }

        private int weeklyPerformanceScore;
        public int WeeklyPerformanceScore
        {
            get { return weeklyPerformanceScore; }
            set { weeklyPerformanceScore = value; }
        }

        private int totalGamingScore;
        public int TotalGamingScore
        {
            get { return totalGamingScore; }
            set { totalGamingScore = value; }
        }

        private int totalPerformanceScore;
        public int TotalPerformanceScore
        {
            get { return totalPerformanceScore; }
            set { totalPerformanceScore = value; }
        }

        public UserProfile()
        {
            this.id = 0;
            this.userId = 0;
            this.realName = string.Empty;
            this.nickName = string.Empty;
            this.city = string.Empty;
            this.dateOfBirth = SqlDateTime.MinValue.Value;
            this.messenger = string.Empty;
            this.facebookProfileUrl = string.Empty;
            this.mood = string.Empty;
            this.playerStyle = string.Empty;
            this.element = string.Empty;
            this.realImageUrl = string.Empty;
            this.isRealImageVerified = false;
            this.avatarImageUrl = string.Empty;
            this.isAvatarImageVerified = false;
            this.favoriteGames = string.Empty;
            this.userBio = string.Empty;
            this.useProfileImage = false;
            this.memberId = string.Empty;
            this.weeklyGamingScore = 0;
            this.weeklyPerformanceScore = 0;
            this.totalPerformanceScore = 0;
            this.totalGamingScore = 0;
        }

        public UserProfile(DataRow dataRow)
        {
            if (dataRow != null)
            {
                if (dataRow.Table.Columns.Contains("ProfileId"))
                    this.id = (int)CommonUtility.FilterNull(dataRow["ProfileId"], typeof(int));
                if (dataRow.Table.Columns.Contains("RealName"))
                    this.realName = (string)CommonUtility.FilterNull(dataRow["RealName"], typeof(string));
                if (dataRow.Table.Columns.Contains("NickName"))
                    this.nickName = (string)CommonUtility.FilterNull(dataRow["NickName"], typeof(string));
                if (dataRow.Table.Columns.Contains("City"))
                    this.city = (string)CommonUtility.FilterNull(dataRow["City"], typeof(string));
                if (dataRow.Table.Columns.Contains("DateOfBirth"))
                    this.dateOfBirth = (DateTime)CommonUtility.FilterNull(dataRow["DateOfBirth"], typeof(DateTime));
                if (dataRow.Table.Columns.Contains("Messenger"))
                    this.messenger = (string)CommonUtility.FilterNull(dataRow["Messenger"], typeof(string));
                if (dataRow.Table.Columns.Contains("FacebookProfileUrl"))
                    this.facebookProfileUrl = (string)CommonUtility.FilterNull(dataRow["FacebookProfileUrl"], typeof(string));
                if (dataRow.Table.Columns.Contains("Mood"))
                    this.mood = (string)CommonUtility.FilterNull(dataRow["Mood"], typeof(string));
                if (dataRow.Table.Columns.Contains("PlayerStyle"))
                    this.playerStyle = (string)CommonUtility.FilterNull(dataRow["PlayerStyle"], typeof(string));
                if (dataRow.Table.Columns.Contains("Element"))
                    this.element = (string)CommonUtility.FilterNull(dataRow["Element"], typeof(string));
                if (dataRow.Table.Columns.Contains("RealImageUrl"))
                    this.realImageUrl = (string)CommonUtility.FilterNull(dataRow["RealImageUrl"], typeof(string));
                if (dataRow.Table.Columns.Contains("IsRealImageVerified"))
                    this.isRealImageVerified = (bool)CommonUtility.FilterNull(dataRow["IsRealImageVerified"], typeof(bool));
                if (dataRow.Table.Columns.Contains("AvatarImageUrl"))
                    this.avatarImageUrl = (string)CommonUtility.FilterNull(dataRow["AvatarImageUrl"], typeof(string));
                if (dataRow.Table.Columns.Contains("IsAvatarImageVerified"))
                    this.isAvatarImageVerified = (bool)CommonUtility.FilterNull(dataRow["IsAvatarImageVerified"], typeof(bool));
                if (dataRow.Table.Columns.Contains("FavoriteGames"))
                    this.favoriteGames = (string)CommonUtility.FilterNull(dataRow["FavoriteGames"], typeof(string));
                if (dataRow.Table.Columns.Contains("UserBio"))
                    this.userBio = (string)CommonUtility.FilterNull(dataRow["UserBio"], typeof(string));
                if (dataRow.Table.Columns.Contains("UseProfileImage"))
                    this.useProfileImage = (bool)CommonUtility.FilterNull(dataRow["UseProfileImage"], typeof(bool));
                if (dataRow.Table.Columns.Contains("MemberId"))
                    this.memberId = (string)CommonUtility.FilterNull(dataRow["MemberId"], typeof(string));
                if (dataRow.Table.Columns.Contains("WeeklyGamingScore"))
                    this.weeklyGamingScore = (int)CommonUtility.FilterNull(dataRow["WeeklyGamingScore"], typeof(int));
                if (dataRow.Table.Columns.Contains("WeeklyPerformanceScore"))
                    this.weeklyPerformanceScore = (int)CommonUtility.FilterNull(dataRow["WeeklyPerformanceScore"], typeof(int));
                if (dataRow.Table.Columns.Contains("TotalPerformanceScore"))
                    this.totalPerformanceScore = (int)CommonUtility.FilterNull(dataRow["TotalPerformanceScore"], typeof(int));
                if (dataRow.Table.Columns.Contains("TotalGamingScore"))
                    this.totalGamingScore = (int)CommonUtility.FilterNull(dataRow["TotalGamingScore"], typeof(int));
            }
            else
            {
                this.id = 0;
                this.userId = 0;
                this.realName = string.Empty;
                this.nickName = string.Empty;
                this.city = string.Empty;
                this.dateOfBirth = SqlDateTime.MinValue.Value;
                this.messenger = string.Empty;
                this.facebookProfileUrl = string.Empty;
                this.mood = string.Empty;
                this.playerStyle = string.Empty;
                this.element = string.Empty;
                this.realImageUrl = string.Empty;
                this.isRealImageVerified = false;
                this.avatarImageUrl = string.Empty;
                this.isAvatarImageVerified = false;
                this.favoriteGames = string.Empty;
                this.userBio = string.Empty;
                this.useProfileImage = false;
                this.memberId = string.Empty;
                this.weeklyGamingScore = 0;
                this.weeklyPerformanceScore = 0;
                this.totalPerformanceScore = 0;
                this.totalGamingScore = 0;
            }
        }

        public bool Update()
        {
            DataFactory.GetDataMiner().BeginTransaction(false);
            bool result = false;
            try
            {
                result = UserData.UpdateUserProfile(this.Id, this.City, this.DateOfBirth, this.Element, 
                    this.FacebookProfileUrl, this.FavoriteGames, 
                    this.Messenger, this.Mood, this.NickName,
                    this.PlayerStyle, this.RealName, this.UseProfileImage,
                    this.UserBio) > 0;

                DataFactory.GetDataMiner().CommitTransaction();
                return result;
            }
            catch (Exception ex)
            {
                DataFactory.GetDataMiner().RollBackTransaction();
                throw ex;
            }
        }
    }
}
